package com.kanshu.ksgb.fastread.doudou.module.login.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;

import com.dl7.recycler.adapter.BaseQuickAdapter;
import com.kanshu.ksgb.fastread.doudou.R;
import com.kanshu.ksgb.fastread.doudou.base.baseui.BaseListFragment;
import com.kanshu.ksgb.fastread.doudou.common.net.bean.PageRequestParams;
import com.kanshu.ksgb.fastread.doudou.module.login.adapter.ChargeAdapter;
import com.kanshu.ksgb.fastread.doudou.module.login.bean.ChargeBean;
import com.kanshu.ksgb.fastread.doudou.common.business.event.BindEvent;
import com.kanshu.ksgb.fastread.doudou.module.personal.presenter.AccountPresenter;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

/**
 * Created by wcy on 2017\6\22 0022.
 */

public class ChargeHistoryFragment extends BaseListFragment<ChargeBean> {

    AccountPresenter mPresenter = new AccountPresenter(lifeCyclerSubject);


    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EventBus.getDefault().register(this);
    }

    @Override
    protected void initRecyclerView() {
        super.initRecyclerView();
        mEmptyLayout.setNoDataTip("您还没有充值记录", R.mipmap.ic_charge_no_data);

    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void handleBindEvent(BindEvent bindEvent) {
        if (bindEvent.code == BindEvent.FAILED) {
            return;
        }
        mList.clear();
        mRequestParams.page = 1;
        mPresenter.getChargeInfos(mRequestParams);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        mPresenter.detachView();
        EventBus.getDefault().unregister(this);
    }

    @Override
    protected BaseQuickAdapter provideAdapter() {
        ChargeAdapter adapter = new ChargeAdapter(getActivity(), mList);
        adapter.setNoMoreDataDesc("");
        return adapter;
    }

    @Override
    protected void getContentAysnc(PageRequestParams params) {
        mPresenter.getChargeInfos(mRequestParams);
    }

    @Override
    protected void updateViews() {
        super.updateViews();
        mPresenter.setChargeView(this);
        mPresenter.getChargeInfos(mRequestParams);
    }

    @Override
    protected boolean isSwipeRefreshEnable() {
        return false;
    }

}
